package asia.kalin.utils;

import asia.kalin.config.QQEmailConfig;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.HtmlEmail;

/**
 * @Author: Kalin
 * @Name：SendEmailUtil
 * @Date: 2025/3/25
 * @description
 */
public class SendEmailUtil {

    /**
     * 发工作人员发送用户反馈
     * @param msg 反馈信息
     * @param username 用户名
     * @throws EmailException
     */
    public static void sendQQEmail(String msg,String username) throws EmailException {
        QQEmailConfig qqEmailConfig = new QQEmailConfig();
        HtmlEmail htmlEmail = new HtmlEmail();
        htmlEmail.setHostName("smtp.qq.com");
        htmlEmail.setCharset("utf-8");
        htmlEmail.setSmtpPort(465);
        htmlEmail.setSSLOnConnect(true);
        htmlEmail.addTo(qqEmailConfig.getToEmail());// 收件人
        htmlEmail.setFrom(qqEmailConfig.getUserEmail());
        htmlEmail.setAuthentication(qqEmailConfig.getUserEmail(),qqEmailConfig.getKey());
        htmlEmail.setSubject(username + "用户反馈");// 发送主题
        htmlEmail.setMsg(msg);
        htmlEmail.send();
    }
}
